home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / nrdump.c < prev    next >
C/C++ Source or Header  |  1991-02-25  |  3KB  |  120 lines

  1. /* @(#) $Header: nrdump.c,v 1.2 91/02/24 20:17:28 deyke Exp $ */
  2.  
  3. /* NET/ROM header tracing routines
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include <stdio.h>
  7. #include "global.h"
  8. #include "mbuf.h"
  9. #include "timer.h"
  10. #include "ax25.h"
  11. #include "netrom.h"
  12. #include "trace.h"
  13.  
  14. /* Display NET/ROM network and transport headers */
  15. void
  16. netrom_dump(fp,bpp,check)
  17. FILE *fp;
  18. struct mbuf **bpp;
  19. int check;
  20. {
  21.     char src[AXALEN],dest[AXALEN];
  22.     char tmp[AXBUF];
  23.     char thdr[NR4MINHDR];
  24.     register i;
  25.  
  26.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  27.         return;
  28.     /* See if it is a routing broadcast */
  29.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  30.         (void)PULLCHAR(bpp);            /* Signature */
  31.         pullup(bpp,tmp,ALEN);
  32.         tmp[ALEN] = '\0';
  33.         fprintf(fp,"NET/ROM Routing: %s\n",tmp);
  34.         for(i = 0;i < NRDESTPERPACK;i++) {
  35.             if (pullup(bpp,src,AXALEN) < AXALEN)
  36.                 break;
  37.             fprintf(fp,"        %12s",pax25(tmp,src));
  38.             pullup(bpp,tmp,ALEN);
  39.             tmp[ALEN] = '\0';
  40.             fprintf(fp,"%8s",tmp);
  41.             pullup(bpp,src,AXALEN);
  42.             fprintf(fp,"    %12s",pax25(tmp,src));
  43.             tmp[0] = PULLCHAR(bpp);
  44.             fprintf(fp,"    %3u\n",uchar(tmp[0]));
  45.         }
  46.         return;
  47.     }
  48.     /* Decode network layer */
  49.     pullup(bpp,src,AXALEN);
  50.     fprintf(fp,"NET/ROM: %s",pax25(tmp,src));
  51.  
  52.     pullup(bpp,dest,AXALEN);
  53.     fprintf(fp,"->%s",pax25(tmp,dest));
  54.  
  55.     i = PULLCHAR(bpp);
  56.     fprintf(fp," ttl %d\n",i);
  57.  
  58.     /* Read first five bytes of "transport" header */
  59.     pullup(bpp,thdr,NR4MINHDR);
  60.     switch(thdr[4] & NR4OPCODE){
  61.     case NR4OPPID:  /* network PID extension */
  62.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  63.             ip_dump(fp,bpp,check) ;
  64.             return;
  65.         }
  66.         else
  67.             fprintf(fp,"         protocol family %x, proto %x",
  68.              uchar(thdr[0]), uchar(thdr[1])) ;
  69.         break ;
  70.     case NR4OPCONRQ:        /* Connect request */
  71.         fprintf(fp,"         conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  72.         i = PULLCHAR(bpp);
  73.         fprintf(fp," wnd %d",i);
  74.         pullup(bpp,src,AXALEN);
  75.         fprintf(fp," %s",pax25(tmp,src));
  76.         pullup(bpp,dest,AXALEN);
  77.         fprintf(fp,"@%s",pax25(tmp,dest));
  78.         break;
  79.     case NR4OPCONAK:        /* Connect acknowledgement */
  80.         fprintf(fp,"         conn ack: ur ckt %d/%d my ckt %d/%d",
  81.          uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  82.          uchar(thdr[3]));
  83.         i = PULLCHAR(bpp);
  84.         fprintf(fp," wnd %d",i);
  85.         break;
  86.     case NR4OPDISRQ:        /* Disconnect request */
  87.         fprintf(fp,"         disc: ckt %d/%d",
  88.          uchar(thdr[0]),uchar(thdr[1]));
  89.         break;
  90.     case NR4OPDISAK:        /* Disconnect acknowledgement */
  91.         fprintf(fp,"         disc ack: ckt %d/%d",
  92.          uchar(thdr[0]),uchar(thdr[1]));
  93.         break;
  94.     case NR4OPINFO: /* Information (data) */
  95.         fprintf(fp,"         info: ckt %d/%d",
  96.          uchar(thdr[0]),uchar(thdr[1]));
  97.         fprintf(fp," txseq %d rxseq %d",
  98.          uchar(thdr[2]), uchar(thdr[3]));
  99.         break;
  100.     case NR4OPACK:  /* Information acknowledgement */
  101.         fprintf(fp,"         info ack: ckt %d/%d",
  102.          uchar(thdr[0]),uchar(thdr[1]));
  103.         fprintf(fp," txseq %d rxseq %d",
  104.          uchar(thdr[2]), uchar(thdr[3]));
  105.         break;
  106.     default:
  107.         fprintf(fp,"         unknown transport type %d",
  108.          thdr[4] & 0x0f) ;
  109.         break;
  110.     }
  111.     if(thdr[4] & NR4CHOKE)
  112.         fprintf(fp," CHOKE");
  113.     if(thdr[4] & NR4NAK)
  114.         fprintf(fp," NAK");
  115.     if(thdr[4] & NR4MORE)
  116.         fprintf(fp," MORE");
  117.     putc('\n',fp);
  118. }
  119.  
  120.